package com.example.stringbufferlogger.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.stringbufferlogger.entity.QueryCompare;
import com.example.stringbufferlogger.entity.ReplayResult;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ReplayResultMapper extends BaseMapper<ReplayResult> {
    /**
     * 根据 requestId 查询 ReplayResult 记录
     * @param requestId 请求 ID
     * @return ReplayResult 记录
     */
    @Select("SELECT * FROM REPLAY_RESULT WHERE request_id = #{requestId}")
    ReplayResult selectByRequestId(String requestId);


    @Select("select a.id,c.interface_no,a.requestbody,b.original_value,b.replay_value,b.diff_flag from " +
            "logrecord a ,replay_result b,interface_mapping_config c where 1=1 " +
            "and a.path = c.old_path  and a.requestid = b.request_id and c.write_flag = 1 " +
            "and c.valid_flag = 1 and a.path = c.old_path and a.requestid = #{requestId}")
    QueryCompare selectResByRequestId(String requestId);

    /**
     * 更新 ReplayResult 记录
     * @param replayResult ReplayResult 实体
     * @return 更新的记录数
     */
    @Update("UPDATE REPLAY_RESULT SET diff_flag = #{diffFlag}, replay_time = #{replayTime} WHERE request_id = #{requestId}")
    int updateByRequestId(ReplayResult replayResult);

}
